home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 June
/
CHIP Haziran 2001.iso
/
prog
/
haziran
/
19
/
setup.exe
/
data.z
/
wdreg.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2001-04-11
|
10KB
|
368 lines
#include <windows.h>
#include <stdarg.h>
#include <stdio.h>
#include "drvload.h"
#include "../../include/windrvr.h"
int main (int argc, char *argv[]);
#ifndef _CONSOLE
char g_sAppName[256];
char g_sBuf[4096];
void OutputMessage()
{
MessageBox( NULL, g_sBuf, g_sAppName, MB_OK | MB_ICONINFORMATION );
}
int printf( char *szFormat, ... )
{
char sBuf[256];
DWORD ret;
va_list marker;
va_start( marker, szFormat );
ret = vsprintf( sBuf, szFormat, marker );
strcat( g_sBuf, sBuf );
va_end( marker );
return ret;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR szCmdLine, int iCmdShow)
{
char argv0[256];
char *argv_all;
char *argv[256];
int ret_val;
int argc = 0;
BOOL fInArg = FALSE;
BOOL fInQuote;
int i,j;
GetModuleFileName(hInstance, argv0, sizeof (argv0));
strcpy( g_sAppName, argv0 );
argv[argc++] = argv0;
argv_all = (char *) malloc (strlen(szCmdLine)+1);
j = 0;
for (i=0; (char) szCmdLine[i]; i++)
{
char ch = (char) szCmdLine[i];
if (fInArg)
{
if (fInQuote && ch=='\"' || !fInQuote && (ch==' ' || ch=='\t'))
{
fInArg = FALSE;
argv_all[j++] = '\0';
}
else
{
argv_all[j++] = ch;
}
}
else
{
if (ch!=' ' && ch!='\t')
{
fInArg = TRUE;
fInQuote = ch=='\"';
if (!fInQuote)
i--;
argv[argc] = argv_all + j;
argc++;
}
}
}
if (fInArg)
argv_all[j++] = '\0';
argv[argc] = NULL;
ret_val = main(argc, argv);
free (argv_all);
return ret_val;
}
#else
void OutputMessage()
{
}
#endif //_CONSOLE
void PrintUsage(char *exe)
{
printf ("%s [Options] Action\n", exe);
printf ("Options:\n");
#ifndef _CONSOLE
printf (" -silent: supresses output message box.\n");
#endif //_CONSOLE
printf (" -startup: Valid only for WinNT.\n");
printf (" Set startup level: boot, system, automatic, manual, disabled\n");
printf (" (default: automatic).\n");
printf (" -name: Set then name of the driver (default: " WD_PROD_NAME ").\n");
printf (" -file: Set the file name of the driver.\n");
printf (" -vxd: load a .vxd on Win98 (default .sys)\n");
printf ("Action:\n");
printf (" create: create a registry entry for the driver.\n");
printf (" start: start the driver.\n");
printf (" install: create + start.\n");
printf (" delete: delete the registry entry for the driver.\n");
printf (" stop: stop the driver.\n");
printf (" remove: stop + delete.\n");
printf ("Examples:\n");
printf (" To load a driver called MPEG Encoder, with file names MPEGENC.VXD and\n");
printf (" MPEGENC.SYS:\n");
printf (" WDREG -name \"MPEG Encoder\" -file MPEGENC -startup manual create start\n");
printf (" is the same as:\n");
printf (" WDREG -name \"MPEG Encoder\" -file MPEGENC -startup manual install\n");
printf ("\n");
printf (" To unload default driver (i.e. " WD_PROD_NAME "), and remove it from registry:\n");
printf (" WDREG stop delete\n");
printf (" is the same as:\n");
printf (" WDREG remove\n");
OutputMessage();
}
int main (int argc, char *argv[])
{
char *sDriverName = NULL;
char *sDriverFile = NULL;
BOOL fQuiet = FALSE;
BOOL fErrComLine = FALSE;
BOOL fVxd = FALSE;
char sErrBuf[1024];
DWORD startup = 2;
LoadDriver *loadDriver = NULL;
int i;
if (argc==1)
{
PrintUsage(argv[0]);
return 0;
}
for (i=1; i<argc; i++)
{
if (argv[i][0]=='-')
{
if (stricmp(argv[i],"-silent")==0)
{
fQuiet = TRUE;
continue;
}
if (stricmp(argv[i],"-vxd")==0)
{
fVxd = TRUE;
continue;
}
if (stricmp(argv[i],"-name")==0)
{
i ++;
if (i==argc)
{
sprintf (sErrBuf, "option '-name' needs a following argument\n");
fErrComLine = TRUE;
break;
}
sDriverName = argv[i];
continue;
}
if (stricmp(argv[i],"-startup")==0)
{
i ++;
if (i==argc)
{
sprintf (sErrBuf, "option '-startup' needs a following argument\n");
fErrComLine = TRUE;
break;
}
if (stricmp(argv[i],"boot")==0)
startup = SERVICE_BOOT_START;
else if (stricmp(argv[i],"system")==0)
startup = SERVICE_SYSTEM_START;
else if (stricmp(argv[i],"automatic")==0)
startup = SERVICE_AUTO_START;
else if (stricmp(argv[i],"manual")==0)
startup = SERVICE_DEMAND_START;
else if (stricmp(argv[i],"disabled")==0)
startup = SERVICE_DISABLED;
else
{
sprintf (sErrBuf,"option '-startup' needs one of the following argument:\n");
sprintf (sErrBuf, " boot, system, automatic , manual, disabled\n");
fErrComLine = TRUE;
break;
}
continue;
}
else if (stricmp(argv[i],"-file")==0)
{
i ++;
if (i==argc)
{
sprintf (sErrBuf, "option '-file' needs a following argument\n");
fErrComLine = TRUE;
break;
}
sDriverFile = argv[i];
continue;
}
else
{
sprintf (sErrBuf, "unknown option %s\n",argv[i]);
fErrComLine = TRUE;
break;
}
}
else break;
}
if( fErrComLine )
{
printf( "%s", sErrBuf );
if (!fQuiet)
OutputMessage();
return EXIT_FAILURE;
}
if (!sDriverName && !sDriverFile)
{
sDriverName = WD_PROD_NAME;
sDriverFile = "WINDRVR";
}
else if (!sDriverName)
{
sDriverName = sDriverFile;
}
else if (!sDriverFile)
{
sDriverFile = sDriverName;
}
int rc = 0;
loadDriver = NewLoadDriver (fVxd);
if (!loadDriver)
{
printf ("ERROR. please check the following:\n");
printf (" Opreating system: This program can run only on Win95/Win98/WinNT\n");
printf (" -vxd option can not be used in WinNT\n");
rc = 1;
goto Exit;
}
if (loadDriver->HasMsg())
printf ("%s", loadDriver->GetLastMsg());
if (loadDriver->HasErr())
{
rc = 1;
goto Exit;
}
if (!loadDriver->Init(sDriverName, sDriverFile, startup))
{
printf ("Init failed\n");
rc = 1;
goto Exit;
}
if (i==argc)
{
printf ("nothing to do!\n");
rc = 0;
goto Exit;
}
for (; i<argc; i++)
{
if (stricmp(argv[i],"create")==0)
{
printf ("Creating driver entry... ");
if (!loadDriver->Create())
{
printf ("Failed\n");
printf ("%s", loadDriver->GetLastMsg());
}
else printf ("OK\n");
}
else if (stricmp(argv[i],"delete")==0)
{
printf ("Deleting driver entry... ");
if (!loadDriver->Delete())
{
printf ("Failed\n");
printf ("%s", loadDriver->GetLastMsg());
}
else printf ("OK\n");
}
else if (stricmp(argv[i],"start")==0)
{
printf ("Starting driver... ");
if (!loadDriver->Start())
{
printf ("Failed\n");
printf ("%s", loadDriver->GetLastMsg());
}
else printf ("OK\n");
}
else if (stricmp(argv[i],"stop")==0)
{
printf ("Stopping driver... ");
if (!loadDriver->Stop())
{
printf ("Failed\n");
printf ("%s", loadDriver->GetLastMsg());
}
else printf ("OK\n");
}
else if (stricmp(argv[i],"install")==0)
{
printf ("Creating driver entry... ");
if (!loadDriver->Create())
{
printf ("Failed\n");
printf ("%s", loadDriver->GetLastMsg());
}
else printf ("OK\n");
printf ("Starting driver entry... ");
if (!loadDriver->Start())
{
printf ("Failed\n");
printf ("%s", loadDriver->GetLastMsg());
}
else printf ("OK\n");
}
else if (stricmp(argv[i],"remove")==0)
{
printf ("Stopping driver entry... ");
if (!loadDriver->Stop())
{
printf ("Failed\n");
printf ("%s", loadDriver->GetLastMsg());
}
else printf ("OK\n");
printf ("Deleting driver entry... ");
if (!loadDriver->Delete())
{
printf ("Failed\n");
printf ("%s", loadDriver->GetLastMsg());
}
else printf ("OK\n");
}
else
{
printf ("unknown option %s\n",argv[i]);
goto Exit;
}
}
Exit:
delete loadDriver;
if (!fQuiet)
OutputMessage();
return rc;
}